package com.cole.gx095.controller;


import com.cole.gx095.Repository.ExwarehouseRepository;
import com.cole.gx095.domain.Extable;
import com.cole.gx095.service.ExhouseService;
import com.cole.gx095.controller.utils.CommonRep;
import com.cole.gx095.entity.Exwarehouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/exHouse")
@CrossOrigin
@Transactional
public class exHouseController {
    @Autowired
    ExwarehouseRepository exhouseRepository;
    @Autowired
    ExhouseService exhouseService;

    @GetMapping("/List")
    CommonRep List(Integer currentPage, Integer pageSize){
        Page<Exwarehouse> page1 = exhouseRepository.findAll(PageRequest.of(currentPage - 1, pageSize));
        Extable extable1 = new Extable("s123","2022-02-11");
        List<Extable> extable = new ArrayList<>();
        extable.add(extable1);
        page1.getContent().get(0).setExtable(extable);
        return CommonRep.ok()
                .data("page",page1)
                .data("purContractList",page1.getContent());
    }
    @PostMapping("/queryBy")
    CommonRep getById( Integer currentPage,
                        Integer pageSize,
                        Exwarehouse exwarehouse){
        System.out.println("currentPage = " + currentPage);
        System.out.println("pageSize = " + pageSize);
        System.out.println("exwarehouse = " + exwarehouse);
        Page<Exwarehouse> allBy = exhouseService.findAllBy(exwarehouse, currentPage, pageSize);
        return CommonRep.ok()
                .data("page",allBy)
                .data("ExList",allBy.getContent());
    }

}
